<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;


class AliWuLiuController extends BaseController
{
    /**
     * 查询物流
     * @param Request $request
     * @param $no 快递单号
     * @return \Illuminate\Http\JsonResponse
     */
    public function kuaidi(Request $request)
    {
        $host = "https://wuliu.market.alicloudapi.com";
        $path = "/kdi";
        $method = "GET";
        $appcode = env('WULIU_APPCODE');
        $headers = array();
        array_push($headers, "Authorization:APPCODE " . $appcode);
        $no = $request->no;//快递单号
        $querys = "no=" . $no;
        $bodys = "";
        $url = $host . $path . "?" . $querys;

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, false);
        if (1 == strpos("$" . $host, "https://")) {
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }
        curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
        $res = curl_exec($curl);
        $data = json_decode($res);

        return $this->success($data);
    }

}
